'use strict';

const Controller = require('egg').Controller;

class RemoveCartController extends Controller {
  async index() {
    const { ctx } = this;
    var {userName , id} = ctx.request.body
    var db = this.app.mongodb
    var res =await db.collection("user-cart").find({userName}).toArray()
    if(res.length){
      await db.collection("user-cart").update({userName},{$pull:{cart:{_id:id}}})
      ctx.body={
        code:200,
        msg:'删除成功'
      }
    }else{
      ctx.body={
        code:400,
        msg:'该商品已经删除！'
      }
    }
  }
}

module.exports = RemoveCartController;
